package com.lksoft.bz.action;

import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

import com.lksoft.bz.Bz;

/**
 * Undo action
 * 
 * @author lake
 *
 */
public class UndoAction extends AbstractAction {
	private static final long serialVersionUID = -6097215894191780576L;
	
	private Bz bz;
	
	/**
	 * @param bz The program
	 * @throws IOException 
	 */
	public UndoAction(Bz bz, String iconPath) throws IOException{
		super("", new ImageIcon(ImageIO.read(Bz.class.getResourceAsStream(iconPath)).getScaledInstance(32, 32, Image.SCALE_SMOOTH)));
		this.bz = bz;
		
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
		putValue(MNEMONIC_KEY, KeyEvent.VK_U);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		bz.undo();
	}

}
